package cn.tp.ksoft.civil_driver.dialog;

import android.content.Context;
import android.util.SparseArray;
import android.view.View;

import java.util.Calendar;

import cn.tp.ksoft.civil_driver.R;

/**
 * Created by zhusong on 16/5/2.
 */
public class DriveAgeDialog extends WheelDialog {

    private final int DEFAULT_MAX_MONTH = 12;

    public DriveAgeDialog(Context context) {
        super(context);
    }

    @Override
    protected void initData() {
        mTitleTv.setText(getContext().getString(R.string.driver_drive_age));
        mWheel1.setVisibility(View.VISIBLE);
        mWheel2.setVisibility(View.VISIBLE);
        mWheel3.setVisibility(View.GONE);
        int currentYear = Calendar.getInstance().get(Calendar.YEAR);
        SparseArray<String> years = new SparseArray<>();
        for (int i = currentYear - 10; i <= currentYear; i++) {
            years.append(i, getContext().getString(R.string.driver_date_year, i));
        }
        mWheelAdapter1.setData(years);
        SparseArray<String> months = new SparseArray<>();
        for (int i = 1; i <= DEFAULT_MAX_MONTH; i++) {
            months.append(i, getContext().getString(R.string.driver_date_month, i));
        }
        mWheelAdapter2.setData(months);
    }

    @Override
    protected void onPositiveClick() {
        if(null != mCallBack) {
            mCallBack.onPositiveClick(mWheelAdapter1.getKey(mWheel1.getCurrentItem()),
                    mWheelAdapter2.getKey(mWheel2.getCurrentItem()));
        }
    }

}
